﻿<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="~/UserControls/ImageThumbnail.ascx" %>

<%@ Import Namespace="SubSonic" %>
<%@ Import Namespace="ClubStarterKit.Data" %>
<%@ Register TagPrefix="Club" TagName="WebContent" Src="~/UserControls/WebContent.ascx" %>

<script runat="server">

    Function ShowDuration(ByVal starttime As Object, ByVal endtime As Object) As String
        Dim starttimeDT As Date = CDate(starttime)
        If Not endtime Is Nothing AndAlso Not IsDBNull(endtime) Then
            Dim endtimeDT As Date = CDate(endtime)
          
            If starttimeDT.Date = endtimeDT.Date Then
                If starttimeDT = endtimeDT Then
                    Return starttimeDT.ToString("h:mm tt")
                Else
                    Return starttimeDT.ToString("h:mm tt") & " - " & endtimeDT.ToString("h:mm tt")
                End If
            Else
                Return "thru " & endtimeDT.ToString("d")
            End If
        Else
            Return starttimeDT.ToString("h:mm tt")
        End If
        
    End Function
    
    Sub Logout_click(ByVal sender As Object, ByVal e As EventArgs)
        FormsAuthentication.SignOut()
        Response.Redirect("Default.aspx")
        
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        delblock.Visible = User.Identity.IsAuthenticated
        If User.Identity.IsAuthenticated Then
            Dim manusers As ClubStarterKit.Web.Controls.RolloverLink = CType(lv1.FindControl("manageusers"), ClubStarterKit.Web.Controls.RolloverLink)
            Dim sendmail As ClubStarterKit.Web.Controls.RolloverLink = CType(lv1.FindControl("sendemail"), ClubStarterKit.Web.Controls.RolloverLink)
            Dim ss As ClubStarterKit.Web.Controls.RolloverLink = CType(lv1.FindControl("sitesettings"), ClubStarterKit.Web.Controls.RolloverLink)
            manusers.Visible = Page.User.IsInRole("Administrators")
            sendmail.Visible = Page.User.IsInRole("Administrators")
            ss.Visible = Page.User.IsInRole("Administrators")
        End If
    End Sub
    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ClubStarterKit.Web.Members.DeleteUser()
        FormsAuthentication.SignOut()
        Response.Redirect("~/Default.aspx")
    End Sub
    
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager id="ScriptManager1" runat="server"></asp:ScriptManager><div id="body">
        <div id="columnleft">
            <a title="content_start" id="content_start"></a>
            <div class="leftblock">
                <asp:LoginView ID="lv1" runat="server">
                    <AnonymousTemplate>
                        <h2>Login</h2>
                        <div class="dashedline">
                        </div>
                        <asp:Login ID="Login1" runat="server">
                    <LayoutTemplate>
                            <asp:Literal runat="server" ID="FailureText" EnableViewState="False"></asp:Literal>

                            <table>
                                <tr>
                                    <td>
                                        <asp:Label runat="server" AssociatedControlID="UserName" ID="UserNameLabel">User name:</asp:Label></td>
                                    <td>
                                        <asp:TextBox runat="server" ID="UserName"></asp:TextBox>
                                        <asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" ValidationGroup="Login1"
                                            ErrorMessage="User Name is required." ToolTip="User Name is required." ID="UserNameRequired">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label runat="server" AssociatedControlID="Password" ID="PasswordLabel">Password:</asp:Label></td>
                                    <td>
                                        <asp:TextBox runat="server" TextMode="Password" ID="Password"></asp:TextBox>
                                        <asp:RequiredFieldValidator runat="server" ControlToValidate="Password" ValidationGroup="Login1"
                                            ErrorMessage="Password is required." ToolTip="Password is required." ID="PasswordRequired">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:CheckBox runat="server" ID="RememberMe" Text="Remember me next time." /></td>
                                </tr>
                            </table>

                            <Club:RolloverButton ID="LoginButton" runat="server" Text="Login" CommandName="Login" />
                        </LayoutTemplate>
                </asp:Login>
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                        <h2>
                            Hello
                            <asp:LoginName ID="LoginName1" runat="server" />
                        </h2>
                        <p>
                            <Club:WebContent ID="WebContent1" Section="Welcomeback" runat="server" />
                        </p>
                        <br />
                         <Club:RolloverLink ID="edit" runat="server" NavigateURL="~/member/details.aspx" Text="My Details" />
                    <br />
                    <Club:RolloverLink ID="sitesettings" runat="server" NavigateURL="~/admin/Settings.aspx" Text="Site Settings" />
                    <Club:RolloverLink ID="manageusers" runat="server" NavigateURL="~/admin/ManageUsers.aspx" Text="Manage Users" />
                    <Club:RolloverLink runat="server" id="sendemail" text="Send Email" NavigateURL="~/Admin/Email.aspx" /><br />
                        <Club:RolloverButton runat="server" id="logout" text="Log off" onclick="logout_click" />
                    </LoggedInTemplate>
                </asp:LoginView>
            </div>
            <div class="leftblock">
                <Club:PollControl ID="PollControl1" runat="server" />
            </div>
            <div class="leftblock" id="delblock" runat="server">
            <h2>
            Delete your membership
            </h2>
        <div class="dashedline">
        </div>
        <p>
            You can cancel your membership in this club by clicking on the button below. If
            you cancel your membership, you will be removed from the roster and will no longer
            receive emails from the club leadership.
        </p>
        <Club:RolloverButton runat="server" ID="btnCancel" Text="Remove" OnClick="btnCancel_Click" />
        <cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="btnCancel" ConfirmText="Are you sure you want to delete your membership?">
        </cc1:ConfirmButtonExtender>
    </div>
        </div>
        <div id="columnright">
            <div class="rightblock">
                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="List" TypeName="ClubStarterKit.Web.News">
                    <SelectParameters>
                        <asp:Parameter Name="pagenum" DefaultValue="1" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                <h2>
                    Recent news</h2>
                <div class="dashedline">
                </div>
                <asp:Repeater ID="DataList1" runat="server" DataSourceID="ObjectDataSource1">
                    <ItemTemplate>
                        <div class="listitem">
                            <div class="thumbnail">
                                <a href='<%# "News/View.aspx?Articleid=" &Cstr( Eval("ID"))%>'>
                                    <Club:ImageThumbnail ID="ImageThumbnail2" runat="server" PhotoID='<%# Eval("photo") %>' />
                                </a>
                            </div>
                            <h3>
                                <a href='<%# "News/View.aspx?Articleid=" &Cstr( Eval("ID"))%>'>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("title") %>' /><br />
                                </a><em>
                                    <asp:Label ID="Label3" Font-Size="Smaller" runat="server" Text='<%# Eval("itemdate","{0:d}") %>' /></em>
                            </h3>
                            <p>
                                <asp:Label ID="Label2" runat="server" Text='<%# truncate(Convert.ToString(Eval("description"))) %>' />
                                <a href='<%# "News/View.aspx?Articleid=" &Cstr( Eval("ID"))%>'>read more &raquo;</a>
                            </p>
                            <div class="clearlist">
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <div class="dashedline">
                    <a style="float:right;padding-top: 10px;" href="RSS/NewsRss.aspx">
                        <asp:Image ID="Image1" SkinID="rss" runat="server" />
                        </a></div>
                <a href="news/list.aspx">Read all news articles »</a> <a href="RSS/NewsRss.aspx">
                </a>
            </div>
            <div class="rightblock">
                <h2>
                    Upcoming Events</h2>
                <div class="dashedline">
                </div>
                <asp:ObjectDataSource ID="UpcomingEventsSource" runat="server" SelectMethod="UpcomingList" TypeName="ClubStarterKit.Web.Events">
                <SelectParameters>
                    <asp:Parameter Name="pagenum" DefaultValue="1" />
                </SelectParameters>
            </asp:ObjectDataSource>
                <asp:GridView AutoGenerateColumns="False" DataSourceID="UpcomingEventsSource" ID="GridView1"
                    runat="server" ShowHeader="False" Width="410px" CssClass="eventlist" GridLines="None">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("id","~/Events/download.ashx?Eventid={0}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="events/view.aspx?eventid={0}"
                            DataTextField="title"></asp:HyperLinkField>
                        <asp:TemplateField HeaderText="id" InsertVisible="False" SortExpression="id">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("starttime", "{0:d}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="LocationName" HeaderText="locationname" SortExpression="LocationName">
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>
                <div class="dashedline">
                    <a style="float:right;padding-top: 10px;" href="RSS/EventRss.aspx">
                        <asp:Image ID="Image2" SkinID="rss" runat="server" />
                    </a></div>
                <a href="Events/Calendar.aspx">View all events &raquo;</a>&nbsp; <a href="RSS/EventRss.aspx">
                </a>
            </div>
            <div class="rightblock">
                <asp:ObjectDataSource ID="BlogsDataSouce" runat="server" SelectMethod="GetAll"
                TypeName="ClubStarterKit.Web.Blogs">
                <SelectParameters>
                    <asp:Parameter Name="pagenum" DefaultValue="1" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="BlogsDataSouce">
                <HeaderTemplate>
                    <h2>Recent Blog Posts</h2>
                    <div class="dashedline">
                </div>
                    
                </HeaderTemplate>
                <ItemTemplate>
                <table cellspacing="0">
                    <tr>
                        <td style="width: 437px; height: 28px">
                            <strong style="font-size:medium;">
                               <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# "~/blogs/post.aspx?id=" & Eval("postid").ToString %>'></asp:HyperLink></strong></td>
                        <td style="width: 437px; height: 28px; text-align: right">
                            &nbsp;<span><asp:Hyperlink ID="Label3" runat="server" Text='<%# ClubStarterKit.Web.Members.FirstAndLastName(Eval("memid")) %>' NavigateUrl='<%# "~/blogs/blogger.aspx?username=" & Membership.GetUser(Eval("memid")).Username() %>' /> | <asp:Label ID="Label4" runat="server" Text='<%# GetFriendlyDate(CDate(Eval("postdate")),True) %>' ></asp:Label></span></td>
                    </tr>
                    <tr>
                        <td style="width: 437px">
                        </td>
                        <td style="width: 437px">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("PostText") %>' ></asp:Label></td>
                    </tr>
                </table>
                </ItemTemplate>
                <FooterTemplate>
                </FooterTemplate>
            </asp:Repeater>
                <div class="dashedline">
                    <a style="float:right;padding-top: 10px;" href="RSS/BlogsRss.aspx">
                        <asp:Image ID="Image3" SkinID="rss" runat="server" />
                    </a>
                </div>
                <a href="blogs/default.aspx">View Blog Posts &raquo;</a>
            </div>
        </div>
        <div class="clear2column">
        </div>
    </div>
</asp:Content>
